Formius.Validator_Container = $.inherit(Formius.Validator_Abstract, {
	/**
	* @var Array
	*/
	_validators: [],

	/**
	* @param Validator_Abstract validator
	* @param String $logic Validator_Container.LOGIC_OR | Validator_Container.LOGIC_OR
	* @param Boolean breakAfter
	* @return Void
	*/
	addValidator: function(validator, logic, breakAfter) {
		if (validator === null) {
			return;
		}
		this._validators.push({
			validator	: validator,
			logic		: logic,
			breakAfter	: breakAfter
		});
	},

	/**
	* @return Array
	*/
	getCode: function () {
		var codes = [];
		$(this._validators).each(function(key, validator) {
			var code = validator['validator'].getCode();
			if (code) {
				codes.push(code);
			}
		});
		return codes;
	},
			
	/**
	* @return Array
	*/
	getMessage: function() {
		var messages = [];

		for (i = 0, len = this._validators.length; i < len; i++) {
			var message = this._validators[i]['validator'].getMessage();
			if ($.isArray(message)) {
				for (var j = 0, len = message.length; j < len; j++) {
					messages.push(message[j]);
				}
			} else if (message) {
				messages.push(message);
			}
		};
		return messages;
	},

	/**
	* @param Mixed value
	* @return Boolean
	*/
	isValid: function(value) {
//		console.log(value);
		var result = true,
			last = this._validators.length;
		for (var position = 0; position < last; position++) {
			var logic = last > 1 && position != last? this._validators[position]['logic']: this.__self.LOGIC_AND,
				isValid = this._validators[position]['validator'].isValid(value);

			if (!isValid) {
				if (logic == this.__self.LOGIC_AND && this._validators[position]['breakAfter']) {
					return false;
				}
			}
			if (isValid && logic == this.__self.LOGIC_OR) {
				return true;
			}
			result = logic == this.__self.LOGIC_OR
				? result || isValid
				: result && isValid;
		}
		return result;
	},
	/**
	 * @return Void
	 */
	reset: function() {
		this._setCode(null);
		$(this._validators).each(function(key, validator) {
			validator['validator'].reset();
		});
	}
}, {
	LOGIC_AND: 'and',
	LOGIC_OR: 'or'
});